﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace ConsoleLog
{
    public partial class ConsoleNativeMethods
    {
        [DllImport("kernel32.dll")]
        public static extern bool AllocConsole();

        [DllImport("kernel32.dll")]
        public static extern bool FreeConsole();
       
        [DllImport("user32")]
        static extern void FlashWindowEx(ref FlashWInfo info);

        [DllImport("user32")]
        static extern void MessageBeep(int type);

        [DllImport("user32")]
        static extern int SetWindowLong(IntPtr hWnd, int nIndex, int newValue);

        [DllImport("user32")]
        static extern int GetWindowLong(IntPtr hWnd, int nIndex);

        [DllImport("kernel32")]
        static extern bool GetConsoleScreenBufferInfo(IntPtr consoleOutput, out ConsoleScreenBufferInfo info);

        [DllImport("kernel32")]
        static extern bool GetConsoleTitle(StringBuilder text, int size);

        [DllImport("kernel32")]
        static extern IntPtr GetConsoleWindow();

        [DllImport("kernel32")]
        static extern IntPtr GetStdHandle(int handle);

        [DllImport("kernel32")]
        static extern int SetConsoleCursorPosition(IntPtr buffer, Coord position);

        [DllImport("kernel32")]
        static extern int FillConsoleOutputCharacter(IntPtr buffer, char character, int length, Coord position, out int written);

        [DllImport("kernel32")]
        static extern bool SetConsoleTextAttribute(IntPtr hConsoleOutput, ConsoleColor wAttributes);

        [DllImport("kernel32")]
        static extern bool SetConsoleTitle(string lpConsoleTitle);

        [DllImport("kernel32")]
        static extern bool SetConsoleCtrlHandler(HandlerRoutine routine, bool add);

        [DllImport("user32")]
        static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);

        [DllImport("user32")]
        static extern bool IsWindowVisible(IntPtr hwnd);

        [DllImport("kernel32")]
        static extern IntPtr CreateConsoleScreenBuffer(int access, int share, IntPtr security, int flags, IntPtr reserved);

        [DllImport("kernel32")]
        static extern bool SetConsoleActiveScreenBuffer(IntPtr handle);

        [DllImport("kernel32")]
        static extern bool WriteConsole(IntPtr handle, string s, int length, out int written, IntPtr reserved);

        [DllImport("kernel32")]
        static extern int GetConsoleCP();

        [DllImport("kernel32")]
        static extern int GetConsoleOutputCP();

        [DllImport("kernel32")]
        static extern bool GetConsoleMode(IntPtr handle, out int flags);

        [DllImport("kernel32")]
        static extern bool SetStdHandle(int handle1, IntPtr handle2);

        [DllImport("user32")]
        static extern IntPtr SetParent(IntPtr hwnd, IntPtr hwnd2);

        [DllImport("user32")]
        static extern IntPtr GetParent(IntPtr hwnd);

        [DllImport("user32")]
        static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter,
                                        int x, int y, int cx, int cy, int flags);

        [DllImport("user32")]
        static extern bool GetClientRect(IntPtr hWnd, ref RECT rect);
    }
}
